//-------------------------------------------------------------------------------------------
#include "cx_stack.h"
#include "cx_memory.h"

QStack * cx_stack_new(QBOOL bIsClear)
{
	return cx_stack_newEx(bIsClear, QNULL);
}

QStack * cx_stack_newEx(QBOOL bIsClear, PFNRELEASE pfnRelease)
{
	QStack * pMe;
//	QList* pList ;
	pMe = (QStack *)cx_malloc(sizeof(QStack));
	if(pMe)
	{
		pMe->m_pstList = cx_list_new(QTRUE);
	}
	 
	return pMe;
}
QINT cx_stack_addRef(QStack * pStack)
{
	return cx_list_addRef(pStack->m_pstList);

}
QINT cx_stack_releaseRef(QStack * pStack )
{
	QINT ret = cx_list_releaseRef(pStack->m_pstList);
	if (0 == ret)
	{
		cx_free(pStack);
		pStack = QNULL;
	}
	return ret;
}

QINT cx_stack_count(QStack * pStack)
{
	return cx_list_count(pStack->m_pstList);
}
QBOOL cx_stack_push(QStack * pStack, QVOID * pObj)
{
	QBOOL ret = cx_list_append(pStack->m_pstList, pObj);
	return ret;
}

QVOID* cx_stack_pop(QStack * pStack)
{
	void* retObj = QNULL;
	QINT nCount = cx_list_count(pStack->m_pstList);
	retObj = cx_list_removeElementAt(pStack->m_pstList, nCount - 1);
	return retObj;
}
